#include<stdio.h>
#include<at89c51ed2.h>
#include<mcs51reg.h>
#include<malloc.h>
#include<stdlib.h>
#include "io.h"
#include "eeprom.h"



/*****************************************************************************/
/**Critical Initialisation. Serial Communication at 19200 baud, XRAM 
 * 1024 bytes activated. This function has reference on Page 41 of 
 * the SDCC Manual*/
void _sdcc_external_startup() {
	AUXR|=0x0C;	/*XRAM 1024 bytes activated*/
	TMOD|=0x20;	/*Timer 1 Mode 2*/
	TH1=0xFD;	/*Timer Value 253 for baud rate 9600*/
	SCON = 0x50;/*SCON: mode 1, 8-bit UART, enable receiver*/
	PCON|=0x80;	/*double baud rate to 19200*/
	TR1 = 1; 	/*Start Timer 1 */
	TI = 1;		/*set TI flag for putchar sequence*/
	RI = 0;		/*clear RI flag for getchar sequence*/
	
}
/*****************************************************************************/
extern void i2c_init(int block_select);
extern void i2c();
extern void i2c_read();
extern int i2c_write();
extern int i2c_sendData(int val);
extern int i2c_readData();
extern void i2c_stop();
extern int i2c_ack();
extern void i2c_noack();

/*****************************************************************************/
/*Implements serial transmit using the polling method*/
void putchar (char c)
{
	while ((SCON & 0x02) == 0);    // wait for TX ready, spin on TI
	SBUF = c;  	// load serial port with transmit value
	TI = 0;  	// clear TI flag
}


/*****************************************************************************/
/*The function uses the putchar() method in an iterative manner to
   * transmit a complete string of characters.At the end of the character string 
   * transmission, a Null character (ASCII 13) is appended to the terminal 
   * output*/
void putstr (char *s)  //had return type int in sample file
{
	int i = 0;
	while (*s){			// output characters until NULL found
		putchar(*s++);
		i++;
	}
	putchar('\n');
	}
	
/*****************************************************************************/
/*Serial Reception using polling method*/	
char getchar ()__critical
{
	
    while (!RI);             
   	RI = 0;			// clear RI flag
	return SBUF;  	// return character from SBUF
}

/*****************************************************************************/







	
	
	
	
	
	
	
	
	
	
	



void main(){
	
int ack;

int readTest;
int * val;
int i;
	
	
	
	
		
			
		ack=eebytew(45,25);	
		//ack=eebyter(45);
		ack=eebytew(1400,125);	
		//ack=eebyter(46);
		ack=eebytew(2047,254);
		//ack=eebyter(47);	
		ack=eebyter(2047);
		
		
		
		
		
		
		
		
		
		
//		if(ack==1){
//			printf("\n\rWrite Sucess!");
//		}
//		else{
//			printf("\n\rWrite Failure");
//		}
//		val=eebyteSeqr(45,3);
//		
//		readTest=eebyter(46);
//		
//		
//		i=0;
//		while(i<3){	
//		printf("%d\t%x\n\r",i,val[i]);
//		i++;
//		}
		
		
		
}




